package com.ruanzhaojun.springboot04.controller.admin;

import com.ruanzhaojun.springboot04.entry.admin.AdminUser;
import com.ruanzhaojun.springboot04.service.admin.AdminUserService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin") // 定义父路径
public class AdminUserController {

    // 注入依赖
    @Resource
    private AdminUserService adminUserService;

    // http://localhost:8080/admin/user/1
    // 处理 /admin/user/{id} 路径的GET请求
    @GetMapping("/user/{id}")
    public ResponseEntity<AdminUser> getUserById(@PathVariable Long id) {
        AdminUser user = adminUserService.getById(id);
        // 如果用户不为空，则返回用户信息
        return user != null ? ResponseEntity.ok(user) : ResponseEntity.status(404).body(null);
    }
}

